package com.hibuy.pc.service.shiro.impl;

import com.hibuy.pc.mapper.shiro.RoleMapper;
import com.hibuy.pc.model.shiro.Role;
import com.hibuy.pc.model.shiro.RolePermission;
import com.hibuy.pc.service.shiro.RolePermissionService;
import com.hibuy.pc.service.shiro.RoleService;
import com.sun.org.apache.bcel.internal.generic.NEW;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * Created by admin on 2017/12/28.
 */
@Service
public class RoleServiceImpl implements RoleService {

    @Autowired
    private RoleMapper roleMapper;

    @Autowired
    private RolePermissionService rolePermissionService;

    @Override
    public List<Role> getRoles() {
        return roleMapper.getRoles();
    }

    @Override
    public Role addRoles(Role role, String[] permissionIds) {
        Integer rId = roleMapper.addRoles(role).getId();
        for (String permissionId : permissionIds) {
            RolePermission rolePermission = new RolePermission();
            rolePermission.setrId(rId);
            rolePermission.setpId(Integer.valueOf(permissionId));
            rolePermissionService.addRolePermission(rolePermission);
        }
        return role;
    }
}
